layui.use(['layer', 'form', 'table', 'ztree', 'laydate', 'admin', 'ax'], function () {
    var layer = layui.layer;
    var form = layui.form;
    var table = layui.table;
    var $ZTree = layui.ztree;
    var $ax = layui.ax;
    var laydate = layui.laydate;
    var admin = layui.admin;

    /**
     * 系统管理--用户管理
     */
    var MgrUser = {
        tableId: "userTable",    //表格id
        condition: {
            customId: "",
            timeLimit: ""
        }
    };

    /**
     * 初始化表格的列
     */
    MgrUser.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'createTime', sort: true, title: '创建时间'},
            {field: 'amount', sort: true, title: '金额'},
            {field: 'type', sort: true, title: '出入账'},
            {field: 'customId', sort: true, title: '记录员ID'},
            {field: 'customName', sort: true, title: '记录员名称'},
            {field: 'lowerCustomId', sort: true, title: '入账人ID'},
            {field: 'lowerCustomName', sort: true, title: '入账人名称'},
            {field: 'id', hide: true, sort: true, title: '订单编号'},
            {field: 'batchId', sort: true, title: '批次ID'},
            {field: 'customId', sort: true, title: '用户编号'},
            {field: 'rate', sort: true, title: '费率(%)'},
            {field: 'exchangeRate', sort: true, title: '汇率(%)'},
            {field: 'unit', sort: true, title: '币种'},
            {field: 'extract', sort: true, title: '单笔'},
            {field: 'memo', sort: true, title: '名称'},
            {field: 'createBy', sort: true, title: '创建人'},
            {field: 'updateTime', sort: true, title: '更新时间'},
            {field: 'updateBy', sort: true, title: '更新人'},
           // {align: 'center', toolbar: '#tableBar', title: '操作', minWidth: 280}
        ]];
    };

    /**
     * 点击查询按钮
     */
    MgrUser.search = function () {
        var queryData = {};
        table.reload(MgrUser.tableId, {where: queryData});
    };

    // 渲染表格
    var tableResult = table.render({
        elem: '#' + MgrUser.tableId,
        url: Feng.ctxPath + '/order/listByBatch?batchId='+Feng.getUrlParam("batchId"),
        page: true,
        height: "full-98",
        cellMinWidth: 100,
        cols: MgrUser.initColumn(),
        done: function (res, curr, count) {
            var ajax = new $ax(Feng.ctxPath + '/order/summary?batchId='+Feng.getUrlParam("batchId"));
            var result = ajax.start();
            if(result.data!=null){
                $("#inCount").text(result.data.inCount);
                $("#model").text(result.data.model);
                $("#needGive").text(result.data.needGive);
                $("#outCount").text(result.data.outCount);
                $("#residue").text(result.data.residue);
                $("#status").text(result.data.status);
                $("#sumInAmount").text(result.data.sumInAmount);
                $("#sumOutAmount").text(result.data.sumOutAmount);
                $("#time").text(result.data.time);
            }
        }
    });

    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        MgrUser.search();
    });

    // 工具条点击事件
    table.on('tool(' + MgrUser.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;
    });

    // 导出excel
    $('#btnExp').click(function () {
        MgrUser.exportExcel();
    });

    /**
     * 导出excel按钮
     */
    MgrUser.exportExcel = function () {
        var checkRows = table.checkStatus(MgrUser.tableId);
        if (checkRows.data.length === 0) {
            Feng.error("请选择要导出的数据");
        } else {
            table.exportFile(tableResult.config.id, checkRows.data, 'xls');
        }
    };
});
